package day18;

public class SinglePractice02 {
    public static void main(String[] args) {
        GreatDragon dragon1 = GreatDragon.getG();
        GreatDragon dragon2 = GreatDragon.getG();
        GreatDragon dragon3 = GreatDragon.getG();
        dragon1.killed();
        dragon2.killed();
        dragon3.killed();
    }
}
class GreatDragon implements Runnable{
    private GreatDragon(){}
    private static GreatDragon G;
    public static GreatDragon getG(){
        if (G==null){
            G=new GreatDragon();
        }
        return G;
    }
    static int boold=1000;
    public void killed(){
        while (true){
            try {
                Thread.sleep(10);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            if (boold>0)
                System.out.println("大龙还有"+boold--+"点血");
            if (boold<=0){
                System.out.println("大龙已死,有事烧纸");
                return;
            }
        }
    }
    Object o=new Object();
    @Override
    public void run() {
        synchronized (o){
            killed();
        }

    }
}